#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int cnt[N << 2], tag[N << 2];
void pushup(int p) { cnt[p] = cnt[p << 1] + cnt[p << 1 | 1]; }
void addtag(int p, int l, int r) {
  cnt[p] = (r + 1 - l) - cnt[p];
  tag[p] ^= 1;
}
void pushdown(int p, int l, int r) {
  if (tag[p]) {
    int mid = (l + r) >> 1;
    addtag(p << 1, l, mid);
    addtag(p << 1 | 1, mid + 1, r);
    tag[p] = 0;
  }
}
void update(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(p, l, r);
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, p << 1, l, mid);
  if (R > mid) update(L, R, p << 1 | 1, mid + 1, r);
  pushup(p);
}
int query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return cnt[p];
  pushdown(p, l, r);
  int res = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) res += query(L, R, p << 1, l, mid);
  if (R > mid) res += query(L, R, p << 1 | 1, mid + 1, r);
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int op, L, R;
    cin >> op >> L >> R;
    if (L > R) swap(L, R);
    if (op == 0)
      update(L, R, 1, 1, n);
    else
      cout << query(L, R, 1, 1, n) << endl;
  }
  return 0;
}